package com.quick.develop.flowable.framework.convert.instance;

import com.quick.develop.flowable.domain.dto.instance.BpmProcessInstanceDTO;
import com.quick.develop.flowable.domain.instance.BpmProcessInstancePageItemRespVO;
import com.quick.develop.flowable.domain.instance.BpmProcessInstanceRespVO;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.runtime.ProcessInstance;
import com.quick.develop.flowable.domain.vo.system.SysUserDeptVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/** 
 * @description 流程实例 Convert 
 * @author junyuan.liu
 * @date 2022/5/31 14:22
 */ 

@Mapper
public interface BpmProcessInstanceConvert {

    BpmProcessInstanceConvert INSTANCE = Mappers.getMapper(BpmProcessInstanceConvert.class);

    default List<BpmProcessInstancePageItemRespVO> convertPage(List<HistoricProcessInstance> list){
        return convertList1(list);
    }
    
    @Mappings({
            @Mapping(source = "bean.id", target = "processInstanceId"),
            @Mapping(target = "startUserName", expression = "java(cn.hutool.core.map.MapUtil.getStr(bean.getProcessVariables(), \"INITIATOR_NAME\"))")

    })
    BpmProcessInstancePageItemRespVO convert1(HistoricProcessInstance bean);
    
    List<BpmProcessInstancePageItemRespVO> convertList1(List<HistoricProcessInstance> list);


    @Mapping(source = "id", target = "processInstanceId")
    BpmProcessInstanceRespVO convert(HistoricProcessInstance bean);

    List<BpmProcessInstanceRespVO> convertList4(List<HistoricProcessInstance> bean);

    @Mapping(source = "id", target = "processInstanceId")
    BpmProcessInstanceDTO convertDTO(HistoricProcessInstance bean);
    
    List<BpmProcessInstanceDTO> convertDTOList(List<HistoricProcessInstance> bean);

    BpmProcessInstancePageItemRespVO covertOfProInstance(BpmProcessInstancePageItemRespVO respVO);

    List<BpmProcessInstancePageItemRespVO> coverOfProInstanceList(List<BpmProcessInstancePageItemRespVO> list);
    

    
    @Mappings({
            @Mapping(target = "id", ignore = true),
            @Mapping(source = "startUserId", target = "userCode")

    })
    SysUserDeptVO convertStartUser(ProcessInstance bean);
    List<SysUserDeptVO> convertStartUserList(List<ProcessInstance> processInstanceList);


}
